from lib import *
import random
import time

def Timer(func_name:str):
    """
    计时器装饰器
    """
    def inner_timer(func):
        def inner(*args,**kargs):
            t1=time.time()
            result=func(*args,**kargs)
            t2=time.time()
            print(f"{func_name} cost {t2-t1:0.6f}s")
            return result
        return inner
    return inner_timer


def IntGenerator(num:int=500,rho:float=0.2):
    """
    不重复整数生成器
    Args:
        num: 列表大小，default 500
        rho: 随机采样率，default 0.2
    """
    memory=set()
    Rrange = num/rho//2
    while num:
        num-=1
        a = random.randint(-1*Rrange,Rrange)
        while a in memory:
            a = random.randint(-1*Rrange,Rrange)
        memory.add(a)
        yield a

def main():
    lst=[i for i in IntGenerator()]
    true_sort=sorted(lst)
    print(f"length of list: {len(lst)}")
    funcs=(bubble,select,insert,shell,merge,quick)
    for func in funcs:
        @Timer(func.__name__)
        def test_func(func):
            return func(lst)
        if test_func(func)==true_sort:
            print(f"{func.__name__} pass")
        else:
            print(f"{func.__name__} error")

if __name__ == "__main__":
    main()